package com.lzh.farmbreak;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Display;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;

public class GameActivity extends Activity {

	private MediaPlayer gameMusic;	
	private static int screenWidth;
	private static int screenHight;
	
	private void addGameMusic() 
	{		
		gameMusic = MediaPlayer.create(this,R.raw.gamemusic); 
		gameMusic.setLooping(true);			//鐠佸墽鐤嗗顏嗗箚閹绢厽鏂�
		if(MainActivity.isSound)			//婵″倹鐏夐棅鍏呯閹绱戦崗铏Ц瀵拷娈�
			gameMusic.start();				//閹绢厽鏂佸〒鍛婂灆闂婏拷 
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		// 脠芦脝脕脧脭脢戮麓掳驴脷
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
			WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		// 禄帽脠隆脝脕脛禄驴铆赂脽
		Display display = getWindowManager().getDefaultDisplay();
		
		screenWidth = display.getWidth(); 
		screenHight = display.getHeight();
		// 鑴ц劖鑴㈡埉鑴宠劖闇茬瘬鑴皳纰岃剾鑴劍鑴ц矾View
		AnimationView mAnimView = new AnimationView(this,screenWidth,screenHight);
		setContentView(mAnimView);
	    addGameMusic();
	}

	/*@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_game, menu);
		return true;
	}*/

	public static int getScreenWidth() {
		return screenWidth;
	}

	public static int getScreenHight() {
		return screenHight;
	}
	
	
	@Override
	protected void onPause()//活动为暂停态，被其他运行态的活动取代在屏幕前台显示
	{
		super.onPause();
		if(MainActivity.isSound)//if the switch is on
		{
			if(gameMusic!=null&&gameMusic.isPlaying())//如果当时正在播放
				gameMusic.pause();		//暂停
		}
	}
	@Override
	protected void onResume()//活动为恢复状态
	{
		super.onResume();
		if(MainActivity.isSound)//if the switch is on
		{
			if(gameMusic!=null&&!gameMusic.isPlaying())//如果当时不在播放
				gameMusic.start();		//重新播放
		}
	}
}
